<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "device-deviceCheck",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	gender: [
		{ label: t("男"), value: 0 },
		{ label: t("女"), value: 1 },
		{ label: t("未知"), value: 2 },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("设备序列号"),
			prop: "equipment",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("测量时间"),
			prop: "measurementTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
			},
			span: 12,
		},
		{
			label: t("姓名"),
			prop: "name",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("性别"),
			prop: "gender",
			component: { name: "el-radio-group", options: options.gender },
			value: 2,
			required: true,
		},
		{
			label: t("出生日期"),
			prop: "birthdate",
			component: {
				name: "el-date-picker",
				props: { type: "date", valueFormat: "YYYY-MM-DD" },
			},
			span: 12,
		},
		{
			label: t("手机号码"),
			prop: "phoneNumber",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("身份证号"),
			prop: "idCard",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("医院ID"),
			prop: "hospitalID",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("编号"),
			prop: "number",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("任务ID"),
			prop: "taskID",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼AL"),
			prop: "odAL",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("右眼ALCR"),
			prop: "odALCR",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("右眼AL源数据"),
			prop: "odALSrc",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼AST"),
			prop: "odAST",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼K1"),
			prop: "odK1",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼K2"),
			prop: "odK2",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼PD"),
			prop: "odPD",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("右眼SD"),
			prop: "odSD",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("右眼WTW"),
			prop: "odWTW",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("左眼AL"),
			prop: "osAL",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("左眼ALCR"),
			prop: "osALCR",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("左眼AL源数据"),
			prop: "osALSrc",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("左眼AST"),
			prop: "osAST",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("左眼K1"),
			prop: "osK1",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("左眼K2"),
			prop: "osK2",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("左眼PD"),
			prop: "osPD",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("左眼SD"),
			prop: "osSD",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("左眼WTW"),
			prop: "osWTW",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("备注"),
			prop: "comment",
			component: {
				name: "el-input",
				props: { type: "textarea", rows: 4 },
			},
		},
		{
			label: t("时长"),
			prop: "duration",
			hook: "number",
			component: { name: "el-input-number", props: { min: 0 } },
			span: 12,
		},
		{
			label: t("班级"),
			prop: "klass",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("学生编号"),
			prop: "studentCode",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("学生ID"),
			prop: "studentID",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("用户名"),
			prop: "username",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("密码"),
			prop: "password",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: t("设备序列号"), prop: "equipment", minWidth: 140 },
		{
			label: t("测量时间"),
			prop: "measurementTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{ label: t("姓名"), prop: "name", minWidth: 140 },
		{
			label: t("性别"),
			prop: "gender",
			minWidth: 120,
			dict: options.gender,
		},
		{
			label: t("出生日期"),
			prop: "birthdate",
			minWidth: 140,
			sortable: "custom",
			component: {
				name: "cl-date-text",
				props: { format: "YYYY-MM-DD" },
			},
		},
		{ label: t("手机号码"), prop: "phoneNumber", minWidth: 140 },
		{ label: t("身份证号"), prop: "idCard", minWidth: 140 },
		{ label: t("医院ID"), prop: "hospitalID", minWidth: 140 },
		{ label: t("编号"), prop: "number", minWidth: 140 },
		{ label: t("任务ID"), prop: "taskID", minWidth: 140 },
		{ label: t("右眼AL"), prop: "odAL", minWidth: 140, sortable: "custom" },
		{
			label: t("右眼ALCR"),
			prop: "odALCR",
			minWidth: 140,
			sortable: "custom",
		},
		{ label: t("右眼AL源数据"), prop: "odALSrc", minWidth: 140 },
		{ label: t("右眼AST"), prop: "odAST", minWidth: 140 },
		{ label: t("右眼K1"), prop: "odK1", minWidth: 140 },
		{ label: t("右眼K2"), prop: "odK2", minWidth: 140 },
		{ label: t("右眼PD"), prop: "odPD", minWidth: 140, sortable: "custom" },
		{ label: t("右眼SD"), prop: "odSD", minWidth: 140 },
		{
			label: t("右眼WTW"),
			prop: "odWTW",
			minWidth: 140,
			sortable: "custom",
		},
		{ label: t("左眼AL"), prop: "osAL", minWidth: 140, sortable: "custom" },
		{
			label: t("左眼ALCR"),
			prop: "osALCR",
			minWidth: 140,
			sortable: "custom",
		},
		{ label: t("左眼AL源数据"), prop: "osALSrc", minWidth: 140 },
		{ label: t("左眼AST"), prop: "osAST", minWidth: 140 },
		{ label: t("左眼K1"), prop: "osK1", minWidth: 140 },
		{ label: t("左眼K2"), prop: "osK2", minWidth: 140 },
		{ label: t("左眼PD"), prop: "osPD", minWidth: 140, sortable: "custom" },
		{ label: t("左眼SD"), prop: "osSD", minWidth: 140 },
		{
			label: t("左眼WTW"),
			prop: "osWTW",
			minWidth: 140,
			sortable: "custom",
		},
		{
			label: t("备注"),
			prop: "comment",
			showOverflowTooltip: true,
			minWidth: 200,
		},
		{
			label: t("时长"),
			prop: "duration",
			minWidth: 140,
			sortable: "custom",
		},
		{ label: t("班级"), prop: "klass", minWidth: 140 },
		{ label: t("学生编号"), prop: "studentCode", minWidth: 140 },
		{ label: t("学生ID"), prop: "studentID", minWidth: 140 },
		{ label: t("用户名"), prop: "username", minWidth: 140 },
		{ label: t("密码"), prop: "password", minWidth: 140 },
		{
			label: t("创建时间"),
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" },
		},
		{
			label: t("更新时间"),
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{ type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.device.deviceCheck,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
